﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using nRoute.Components;
using nRoute.SiteMaps;
using nRoute.ViewModels;

namespace nRouteWizard.ViewModels
{
	[MapViewModel(typeof(MainPage))]
	public class MainPageViewModel : ViewModelBase
	{
		public MainPageViewModel()
		{
			LoadSiteMap();
		}

		public IEnumerable<SiteMapNode> SiteMapNodes { get; private set; }

		#region Helpers

		private void LoadSiteMap()
		{
			// SiteMaps are loaded asynchronously 
			SiteMapService.LoadSiteMap((s) =>
			{
				if (s != null && s.RootNode != null)
				{
					this.SiteMapNodes = s.RootNode.ChildNodes;
					NotifyPropertyChanged(() => SiteMapNodes);
				}
			});
		}

		#endregion

	}
}